package com.sys.base.action;

import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.BeanUtils;

import com.sys.dao.model.GftUserInfo;
import com.sys.plat.web.core.BaseAction;
import com.sys.web.util.SystemUtil;

public abstract class BaseGftAction extends BaseAction {
    /**
     * 自动填充 enterpriseId,creatorId,creatorName,createDate, updateId,updateName,updateDate;
     * @param obj
     */
    public void updatePo(Object obj){
        GftUserInfo userInfo = SystemUtil.getLoginUser().getGftUserInfo();
        try {
            String id = BeanUtils.getProperty(obj, "id");
            if (id != null && id.length() > 0) { // 更新
                BeanUtils.setProperty(obj, "updateId", userInfo.getId());
                BeanUtils.setProperty(obj, "updateName", userInfo.getUserName());
            } else {
                BeanUtils.setProperty(obj, "creatorId", userInfo.getId());
                BeanUtils.setProperty(obj, "creatorName", userInfo.getUserName());
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
}
